<?php

namespace common\models\customInfo;

use Yii;
use yii\helpers\ArrayHelper;

/**
 * This is the model class for table "custom_info".
 *
 * @property integer $info_id
 * @property string $token
 * @property string $wecha_id
 * @property integer $ac_id
 * @property string $add_time
 * @property string $user_name
 * @property string $phone
 * @property string $sub_info
 * @property string $work
 * @property integer $user_id
 * @property integer $status
 * @property string $code
 */
class CustomInfo extends \yii\db\ActiveRecord
{
    public $erm;
    private $_statusLabel;
    const STATUS_ERROR = 0; //报名中
    const STATUS_DAIZHIFU = 1; //报名成功，待支付
    const STATUS_SUCCESS = 2; //已支付
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'custom_info';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['token', 'wecha_id', 'ac_id', 'add_time', 'user_name', 'phone', 'sub_info'], 'required'],
            [['ac_id', 'user_id','xingming', 'status', 'code','erm'], 'integer'],
            [['sub_info'], 'string'],
            [['token'], 'string', 'max' => 20],
            [['wecha_id'], 'string', 'max' => 30],
            [['add_time', 'phone'], 'string', 'max' => 11],
            [['user_name'], 'string', 'max' => 35],
            [['work'], 'string', 'max' => 255],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'info_id' => Yii::t('app', '编号'),
            //'token' => Yii::t('app', 'Token'),
            //'wecha_id' => Yii::t('app', 'Wecha ID'),
            'ac_id' => Yii::t('app', '活动名称'),
            'add_time' => Yii::t('app', '报名时间'),
            'xingming' => Yii::t('app', '姓名'),
            'phone' => Yii::t('app', 'Phone'),
            'sub_info' => Yii::t('app', 'Sub Info'),
            'work' => Yii::t('app', 'Work'),
            'user_id' => Yii::t('app', 'User ID'),
            'status' => Yii::t('app', 'Status'),
            'code1' => '凭证码',
            'code' => '二维码',
        ];
    }
    //获取活动名称
    public function getactivityinfo($ac_id)
    {
        $activity = Yii::$app->db->createCommand('SELECT ac_name FROM activity where ac_id='.$ac_id)->queryOne();
        return $activity['ac_name'];
         
    }
    //调用报名状态
    public function getstatus($info_id)
    {
        $activity = Yii::$app->db->createCommand('SELECT status FROM custom_info where info_id='.$info_id)->queryOne();
        return ($activity['status']==1)?"已报名成功":"申请中";  
    }
    //后台列表页显示报名状态
    public static function getArrayStatus()
    {
        return [
            self::STATUS_SUCCESS => Yii::t('app', '已支付'),
            self::STATUS_DAIZHIFU => Yii::t('app', '待支付'),
            //self::STATUS_ERROR => Yii::t('app', '报名中'),
        ];
    }
    public function getStatusLabel()
    {
        if ($this->_statusLabel === null) {
            $statuses = self::getArrayStatus();
            $this->_statusLabel = array_key_exists($this->status,self::getArrayStatus()) ? $statuses[$this->status] : '无';
        }
        return $this->_statusLabel;
    }
}
